//
//  ComonSheet.swift
//  Exchange
//
//  Created by 孟祥群 on 2018/7/23.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit

class ComonSheet: SelectBaseSheet {
    var model: CommonSheetModel?
    var config:ComonConfig?
    override init(model:SheetModel,coinfig:SelectConfig,titleArr:[String],selectStr:String?,dataSource:SelectmangerDelegate) {
        super.init(model:model,coinfig:coinfig,titleArr: titleArr, selectStr: selectStr, dataSource: dataSource)
        self.model = model as? CommonSheetModel
        self.config = coinfig as? ComonConfig
        self.model?.titleArr = titleArr
        self.model?.curretnStr = selectStr
        self.setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func setUpUI() {
        super.setUpUI()
        var count:Int = 0
        if (model?.titleArr.count)! > 6 {
            count = 6
            config?.canScro = true
        }else {
            count = (model?.titleArr.count)!
            config?.canScro = false
        }
        config?.viewHeight = CGFloat((count + 1))*CGFloat((config?.cellHeight)!) + CGFloat((config?.spaceNumber)!) + (isiPhoneX() ? 34 : 0)
        let height = (kSCREEN_HEIGHT - (config?.viewHeight)!)
        selectView.frame = CGRect(x: 0, y:height, width: kSCREEN_WIDTH, height: (config?.viewHeight)!)
        
        let sheetView = SheetTabelview(config: config!,model:model!, dataSource: self.dataSource!)
        sheetView.themeBackground = ThemeManager.ThemeColorKeys.background
        selectView.addSubview(sheetView)
        sheetView.snp.makeConstraints { (make) in
            make.top.left.right.equalToSuperview()
            make.height.equalTo(count * Int((config?.cellHeight)!))
        }
        
        let cancelBtn = UIButton()
        cancelBtn.setTitle(kText("取消"), for: UIControlState.normal)
        cancelBtn.themeBackground = ThemeManager.ThemeColorKeys.background
        cancelBtn.setTitleColor(config?.cancelColor, for: UIControlState.normal)
        cancelBtn.addTarget(self, action: #selector(cancelBtnAction), for: UIControlEvents.touchUpInside)
        cancelBtn.titleLabel?.font = UIFont.systemFont(ofSize: CGFloat((config?.titleFont)!))
        selectView.addSubview(cancelBtn)
        cancelBtn.snp.makeConstraints { (make) in
            make.height.equalTo(45 + (isiPhoneX() ? 34 : 0))
            make.bottom.equalToSuperview()
            make.left.right.equalToSuperview()
        }
    }
    
    
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
